package com.ruoyi.project.exam.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.IdGen;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.exam.domain.RepoModel;
import com.ruoyi.project.exam.mapper.RepoMapper;
import com.ruoyi.project.exam.service.IRepoService;
import com.ruoyi.project.system.dict.domain.DictType;
import com.ruoyi.project.system.notice.domain.Notice;



/**
 * 题库管理
 * @author Administrator
 *
 */
@Service
public class RepoServiceImpl implements IRepoService{
	@Autowired
	private RepoMapper repoMapper;
	
	@Override
	public List<RepoModel> selectRepoList(RepoModel model) {
		return repoMapper.selectRepoList(model);
	}

	@Override
	public int insertRepo(RepoModel model) {
		model.setId(IdGen.uuid());
		model.setCreateTime(new Date());
		model.setCreateBy(ShiroUtils.getLoginName());
		return repoMapper.insertRepo(model);
	}

	@Override
	public RepoModel selectRepoById(String id) {
		return repoMapper.selectRepoById(id);
	}

	@Override
	public int updateRepo(RepoModel model) {
		model.setUpdateTime(new Date());
		model.setUpdateBy(ShiroUtils.getLoginName());
		return repoMapper.updateRepo(model);
	}

	@Override
	public int deleteRepoByIds(String ids) {
		return repoMapper.deleteRepoByIds(Convert.toStrArray(ids));
	}

	@Override
	public String checkCodeUnique(RepoModel model) {
		String id = StringUtils.isBlank(model.getId())? "-1" : model.getId();
		RepoModel repo = repoMapper.checkCodeUnique(model.getCode());
		if (StringUtils.isNotNull(repo) && !repo.getId().equals(id)) {
			return Constants.DATA_NOT_UNIQUE;
		}
		return Constants.DATA_UNIQUE;
	}

	@Override
	public List<RepoModel> selectAll() {
		return repoMapper.selectAll();
	}

}
